package com.common.demo.hander;

/*import com.alibaba.fastjson.JSON;
import com.mtjx.resp.VfResult;
import com.mtjx.utils.WebUtils;*/
import com.common.demo.util.VfResult;
import com.common.demo.util.WebUtils;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 自定义权限不足处理
 * @author 33117
 * @version 1.0
 * @data 2025/8/29 11:14
 */
@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        //VfResult result = new VfResult<>(HttpStatus.FORBIDDEN.value(), "您的权限不足");
        //将result结果转为json
        String json = VfResult.errorMsg(HttpStatus.FORBIDDEN.value(), "您的权限不足").toString();
        //String json = JSON.toJSONString(result);
        // 处理异常，调用工具类
        WebUtils.renderString(response, json);
    }
}
